<template>
	<u-loading-page :loading="loading" loading-text="身份验证中,请稍后……" loading-mode="spinner"/>
</template>

<script setup>
	import { useUserStore } from '@/store/user'
	import { loginAvoidCode	} from '@/apis/login';
	import { ref } from 'vue';
	
	const userStore = useUserStore()
	
	const loading = ref(true)
	uni.login({
	  provider: 'weixin', // 登录服务提供商
	  onlyAuthorize: true, // 微信登录仅请求授权认证,主要是取code的值传给后端拿token
	  success: (res) => {
			loginAvoidCode(res.code).then(res =>{
					if(res.Token) {
						userStore.setToken(res.Token)
						userStore.getUserInfoAction()
					}else{
						uni.reLaunch({
							url: "/pages/login/index",
						})
					}
				})
			},
		})
</script>

<style>
</style>